package com.touzbi.hss.bo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.touzbi.hss.beans.Patient;
import com.touzbi.hss.dao.AbstractDAOFactory;
import com.touzbi.hss.dao.AbstractPatientDAO;
import com.touzbi.hss.dao.DAOException;
import com.touzbi.hss.pagemanager.AbstractPageManager;

public class PatientListBO implements AbstractPatientListBO {

	private AbstractPatientDAO patientDAO;
	private AbstractPageManager pageManager;
	private String error = null;

	public PatientListBO(AbstractDAOFactory daoFactory,
			AbstractPageManager pageManager, HttpServletRequest req) {
		this.patientDAO = daoFactory.getPatientDAO();
		this.pageManager = pageManager;
	}

	public List<Patient> getPatientList() {
		List<Patient> patients = null;
		int pageNumber = this.pageManager.getPageNumber();
		int pageSize = this.pageManager.getPageSize();
		try {
			patients = this.patientDAO.getPatientList(pageNumber * pageSize,
					pageSize);
		} catch (DAOException e) {
			this.error = e.getMessage();
		}
		return patients;
	}

	public long getPatientCount() {
		return this.patientDAO.getPatientCount();
	}

	public String getError() {
		return this.error;
	}

}
